package de.bazinga.rotw.gameModes;

import com.captiveimagination.jgn.clientserver.JGNClient;
import com.captiveimagination.jgn.clientserver.JGNServer;
import com.jme.math.Vector3f;
import com.jmex.game.state.GameStateManager;

import de.bazinga.rotw.game.RotwGameState;
import de.bazinga.rotw.zombie.Waypoint;
import de.bazinga.rotw.zombie.Zombie;

public class CaptureTheZombie implements GameMode{

	private Zombie[] zombies = new Zombie[2];
	
	
	public CaptureTheZombie() {
		
		/**
		 * Create Zombies
		 */
		Waypoint w = new Waypoint(new Vector3f(-15,-999,-15));
		w.addAdjazentWaypoint(new Waypoint(new Vector3f(15,-999,15)));
		
		zombies[0] = new Zombie(w,0);
		zombies[1] = new Zombie(w,1);
	}
	
	@Override
	public void gameUpdate() {}

	@Override
	public void initClient(JGNClient client) {}

	@Override
	public void initServer(JGNServer server) {}

	
	@Override
	public void playerUpdate() {
		RotwGameState gameState = (RotwGameState)GameStateManager.getInstance().getChild("gameState");
		/**
		 * Collision with a Zombie?
		 */
		for(Zombie z:getZombies()) {
			if(z != null && gameState.getPlayer().hasCollision(z, false)) {
				z.collisionWithPlayer(gameState.getPlayer());
			}
		}		
	}

	@Override
	public void reset() {
		RotwGameState game = ((RotwGameState)GameStateManager.getInstance().getChild("gameState"));
		

		// Reset Zombies
		getZombie(0).getZombieController().resetGroundVector();
		getZombie(1).getZombieController().resetGroundVector();
		getZombie(0).getZombieController().setActive(true);
		getZombie(1).getZombieController().setActive(true);
		
		game.getRootNode().attachChild(getZombie(0));
		game.getRootNode().attachChild(getZombie(1));	
	}
	

	@Override
	public boolean useTeams() {
		// We need Teams!
		return true;
	}

	@Override
	public void playerAction() {}

	
	
	public Zombie[] getZombies() {
		return zombies;
	}

	public Zombie getZombie(int index) {
		return zombies[index];
	}

	public void setZombies(Zombie[] zombies) {
		this.zombies = zombies;
	}
}